package main

import (

	"linker/module"
	"linker/util/mysql"
	"github.com/kataras/iris"
	"fmt"
	"linker/controller"
	"github.com/kataras/iris/mvc"
	"linker/repository"
	"linker/service"
)

func main() {
	dbMap, err := mysql.InitDb()
	if err != nil {
		panic(err)
	}

	mysqlDB:=mysql.NewMysql(dbMap)
	mysqlLink:=module.NewMysqlLink(mysqlDB)

	app := iris.New()
	app.Logger().SetLevel("debug")

	app.OnAnyErrorCode(func(ctx iris.Context) {

		fmt.Println("error happend")
		fmt.Println(ctx)
	})
	main:=mvc.New(app)
	main.Register(mysqlLink)
	main.Handle(new(controller.LinkController))

	test:=mvc.New(app.Party("/test"))
	testRepo:=repository.NewTestRepository(mysqlDB)
	testService:=service.NewTestService(testRepo)
	test.Register(testService)
	test.Handle(new(controller.TestController))
	app.Run(iris.Addr(":8008"))
}